#ifndef CONFIG_H
# define CONFIG_H

#define BIT(n) (1<<n) 

/*************************不可变更***************/
//MQTT报文类型
#define MQTT_MSG_CONNECT (1*16)//连接
#define MQTT_MSG_CONNACK (2*16)//连接确认
#define MQTT_MSG_PUBLISH (3*16)//发布
#define MQTT_MSG_PUBACK  (4*16)//发布收到确认
#define MQTT_MSGG_PUBREC (5*16)//发布收到
#define MQTT_MSG_PUBREL  (6*16)//发布释放
#define MQTT_MSG_PUBCOMP (7*16)//发布完成

#define MQTT_MSG_PINGREQ (12*16)//心跳
#define MQTT_MSG_PINGRESP (13*16)//心跳响应

#define MQTT_MSG_SUBCIRBE (8*16) //订阅主题
#define MQTT_MSG_SUBACK (9*16)   //订阅确认
#define MQTT_MSG_UNSUBSCRIBE (10*16)//取消订阅
#define MQTT_MSG_UNSUBACK (11*16)  //取消订阅确认
#define MQTT_MSG_DISCONNECT (14*16)//断开连接

typedef enum
{
    NETSTA_NONE,//未连接到指定socket
    NETSTA_CONN_SOCKET,//已经连接到指定socket,但是未连接到mqtt服务器
    NETSTA_CONN_MQTT,//已经连接到mqtt服务器
}EM_NETSTA;

//连接标志位
#define MQTT_USERNAME_FLAG BIT(7)
#define MQTT_PASSWORD_FLAG BIT(6)
#define MQTT_CLEAN_SESSION BIT(1)
#define MQTT_RETAIN_FLAG BIT(0)
/*******************************************************/


/*****************************可配置********************/
#define MAX_SEND_BUFF_SIZE 200
#define MAX_RECEIVE_BUFF_SIZE 200

//默认ip 地址和端口号
#define SOCKET_IP_DEFAULT  "192.168.148.128"
#define SOCKET_PORT_DEFAULT "1883"


//接入用户配置
#define CLIENT_ID  "baymax_test"
#define USER_NAME  "baymax"
#define USER_PASSWD     "12345678"

//心跳间隔 s
#define KEEP_ALIVE 200

//发布主题
#define TOPIC_PUBLISH "testtopic/2"

//订阅主题
#define TOPIC_SUBCIRBE "testtopic/#"


//控制是否打印从mqtt服务器获得的原始数据
#define PRINT_ORIG_SERVER_DATA 0
/*****************************************************/




void config_init(int argc,char *argv[]);

void config_error_handling(char *message);
void config_printf_hex(char *message,int len);
char* config_get_cur_time();

int config_get_cur_socket();
EM_NETSTA config_get_connect_sta();
void config_set_connect_sta(EM_NETSTA sta);

int config_tcp_socket_connect();
int config_tcp_socket_disconnect(int socket);

int config_mqtt_read(int sockfd,char *packet,int packet_length);
int config_mqtt_write(int sockfd,char *packet,int packet_length);


#endif